package site.marqstree.kotlin.library.good.ui.activity.detail.tabs.tabinfor

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import kotlinx.android.synthetic.main.frag_good_detail_info.*
import q.rorbin.badgeview.QBadgeView
import site.marqstree.kotlin.library.base.ui.fragment.BaseARouterFragment
import site.marqstree.kotlin.library.base.ui.widget.recyclerview.ImageAdapter
import site.marqstree.kotlin.library.base.util.rxbus.RxBus
import site.marqstree.kotlin.library.good.R
import site.marqstree.kotlin.library.good.ui.activity.detail.sku.event.EventSkuChange
import site.marqstree.kotlin.library.good.ui.activity.detail.sku.GoodsSkuPopWin
import site.marqstree.kotlin.library.good.ui.activity.detail.sku.event.EventAddCart
import site.marqstree.kotlin.library.good.ui.bean.GoodDetailBean


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.activity.detail.tabs.tabinfor
 * 文件名: FragGoodInfo
 * 创建者: marqstree
 * 创建时间: 2020/3/14 16:20
 * 描述: TODO
 */
@Route(path = "/good/fragment/goodinfo")
class FragGoodInfo : BaseARouterFragment(){

    @Autowired
    @JvmField var mImages: List<String>? = null

    @Autowired
    @JvmField var mGoodDetailBean: GoodDetailBean? = null

    private val mAdapter: ImageAdapter by lazy{
        ImageAdapter(mImages!!.toMutableList())
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        super.onCreateView(inflater, container, savedInstanceState)
        return inflater.inflate(R.layout.frag_good_detail_info, null)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initRecyclerView()
        mMoreIcon.setOnClickListener {
            GoodsSkuPopWin(activity!!, mGoodDetailBean!!).show()
        }

        RxBus.observe<EventSkuChange>()
            .subscribe{
                mSkuSelectedTv.text = it.mSelectedSku
                mGoodDetailBean?.skus = it.mSkus
            }
    }

    private fun initRecyclerView() {
        val manager = GridLayoutManager(context, 1)
        mRvGoodInfo.layoutManager = manager
        mRvGoodInfo.adapter = mAdapter
    }
}